﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using J2i.Net.Ntp;
using System.IO.IsolatedStorage;

namespace Synchronize
{
    public partial class Page1 : PhoneApplicationPage
    {
        public Page1()
        {
            InitializeComponent();

            // загрузим выбранный сервер
            switch (Synchronize.MainPage.server_ntp)
            {
                case 1:
                    radioButton1.IsChecked = true;
                break;
                case 0:
                    radioButton2.IsChecked = true;
                break;
                case 2:
                    radioButton3.IsChecked = true;
                break;
                case 3:
                    radioButton4.IsChecked = true;
                break;
                case 4:
                    radioButton5.IsChecked = true;
                break;
                case 5:
                    radioButton6.IsChecked = true;
                break;
                case 6:
                    radioButton7.IsChecked = true;
                break;
            }
        }

        private void radioButton2_Checked(object sender, RoutedEventArgs e)
        { //
            Synchronize.MainPage._ntpClient.another_server(Synchronize.MainPage._ntpClient.NtpServerList[0]);
            Synchronize.MainPage.server_ntp = 0;
        }

        private void radioButton1_Checked(object sender, RoutedEventArgs e)
        {
            Synchronize.MainPage._ntpClient.another_server(Synchronize.MainPage._ntpClient.NtpServerList[1]);
            Synchronize.MainPage.server_ntp = 1;
        }

        private void radioButton3_Checked(object sender, RoutedEventArgs e)
        {
            Synchronize.MainPage._ntpClient.another_server(Synchronize.MainPage._ntpClient.NtpServerList[2]);
            Synchronize.MainPage.server_ntp = 2;
        }

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            Synchronize.MainPage._ntpClient.another_server(Synchronize.MainPage._ntpClient.NtpServerList[3]);
            Synchronize.MainPage.server_ntp = 3;
        }

        private void RadioButton_Checked_1(object sender, RoutedEventArgs e)
        {
            Synchronize.MainPage._ntpClient.another_server(Synchronize.MainPage._ntpClient.NtpServerList[4]);
            Synchronize.MainPage.server_ntp = 4;
        }

        private void RadioButton_Checked_2(object sender, RoutedEventArgs e)
        {
            Synchronize.MainPage._ntpClient.another_server(Synchronize.MainPage._ntpClient.NtpServerList[5]);
            Synchronize.MainPage.server_ntp = 5;
        }

        private void RadioButton_Checked_3(object sender, RoutedEventArgs e)
        {
            Synchronize.MainPage._ntpClient.another_server(Synchronize.MainPage._ntpClient.NtpServerList[6]);
            Synchronize.MainPage.server_ntp = 6;
        }

        private void RadioButton_Checked_4(object sender, RoutedEventArgs e)
        {

        }

        private void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            Synchronize.MainPage._ntpClient.another_server(Synchronize.MainPage._ntpClient.NtpServerList[6]);
            Synchronize.MainPage.server_ntp = 6;
        }

        private void server_Loaded(object sender, RoutedEventArgs e)
        {
            // загрузим выбранный сервер
            switch (Synchronize.MainPage.server_ntp)
            {
                case 1:
                    radioButton1.IsChecked = true;
                    break;
                case 0:
                    radioButton2.IsChecked = true;
                    break;
                case 2:
                    radioButton3.IsChecked = true;
                    break;
                case 3:
                    radioButton4.IsChecked = true;
                    break;
                case 4:
                    radioButton5.IsChecked = true;
                    break;
                case 5:
                    radioButton6.IsChecked = true;
                    break;
                case 6:
                    radioButton7.IsChecked = true;
                    break;
            }
        }
    }
}